Skip to content

fix(authserver): one client-metadata validator for the admin API and /oauth2/register; token revocation in the body; docs match the server (#344) - #361

Merged
dfcoffin merged 14 commits into
mainfrom
fix/344-shared-client-validation
Dec 1, 2026
Merged

dfcoffin merged 14 commits into
mainfrom
fix/344-shared-client-validation

Conversation

@dfcoffin

@dfcoffin dfcoffin commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

#344 part 3b, the last part, per the owner's design of 2026-11-30 (decision). Part 3a was PR #359.

Closes #344
Closes #343
Closes #355
Closes #360

D2: one client-metadata validator for the admin API and /oauth2/register

ClientMetadataValidator holds the rules both ways of registering a client share:

Rule Before (admin API) Before (/oauth2/register) Now (both)
Grant types three allowed authorization_code (+ refresh_token) authorization_code, client_credentials, refresh_token
Authentication methods client_secret_basic, client_secret_post, none (#332) client_secret_basic the three, and a public client (none only) cannot use client_credentials
Redirect URIs starts with http:// or https://, in every profile https only where espi.security.require-https-redirect-uris is set at least one for authorization_code; an absolute http(s) URI with a host and no fragment; https only where the flag is set (#298). Post-logout redirect URIs too
Scopes anything; a non-ESPI scope was only logged the Third Party allow-list none blank, and each one the client could be granted through its own grant types, by the token endpoint's rule (EspiGrantScopePolicy): administrative for client_credentials, customer for authorization_code
  • Policies: SELF_REGISTRATION adds the Third Party's own limits (as before): authorization_code with an optional refresh_token, response_types code, client_secret_basic, and the ESPI Third Party scopes. ADMINISTRATOR is the admin API's.
  • Errors: registration answers RFC 7591's invalid_redirect_uri or invalid_client_metadata. The admin API answers 400 invalid_request.
  • Admin update: the redirect URIs and scopes it sets are checked by the same rules, against the client's grant types, inside the locked transaction, so a refusal rolls it back. What it leaves unchanged is not checked, so a client stored before these rules (e.g. the seeded utility_admin_portal) can still be renamed.
  • New refusals by the admin API:
    • a scope its grants could never yield, e.g. DataCustodian_Admin_Access on an authorization_code client;
    • an authorization_code client with no redirect URI;
    • a redirect URI with a fragment, or without a host.

#360: token revocation no longer puts the token in the URL

DELETE /admin/oauth2/tokens/{tokenId} is now POST /admin/oauth2/tokens/revoke with token in a form body, as RFC 7009's /oauth2/revoke sends it. A request with a query string is 400, and the token is never looked up.

#355 (D4): stored-status reporting objects dropped

PostgreSQL V14 drops the objects that counted a client on a timed suspension as active:

  • the views v_active_clients, v_security_monitoring (which also reported the retired failure_count) and v_active_client_certificates;
  • the function check_security_violations();
  • the partial index idx_v_active_clients_status.

No code read them. The drops use no CASCADE, so anything depending on them would fail the migration rather than vanish. The MySQL V3–V6 scripts that create the same objects are .disabled (#145) and must leave them out when they are re-enabled.

#343: docs

  • openapi.yaml:
    • It describes every /admin/oauth2 endpoint the controllers serve, with the server's schemas: PagedClientResponse, ClientDetails, UpdateClientStatusRequest, the client API's error body, and the delete and revocation responses.
    • The camelCase ClientListResponse / ClientResponse and the stale 409, 422 and 429 responses are gone.
    • Its introduction no longer claims OIDC, certification or certificate clients, and the bearer format is opaque.
    • The parts not checked against the server (DataCustodian integration, /userinfo, the OAuth endpoints) are marked so.
  • ClientManagementOpenApiTest now checks:
    • the response schemas against the DTOs;
    • that the spec lists exactly the /admin/oauth2 endpoints the two controllers serve, read from their mapping annotations;
    • that every $ref resolves.
  • API_DOCUMENTATION.md:
    • points to the one client API guide instead of keeping a second, wrong copy;
    • documents the real error formats;
    • certificate clients: not available;
    • rate limiting: not implemented;
    • removes the SDK section, since those SDKs do not exist.
  • INTEGRATION_GUIDE.md:
    • no tls_client_auth example;
    • the shared registration rules;
    • an opaque token response with the ESPI URIs and no id_token.
  • OAUTH2_CLIENT_MANAGEMENT_API.md:
    • the shared rules;
    • token revocation in the form body;
    • 404 with no body;
    • no Upload_Admin_Access in the example.

Tests

  • ClientMetadataValidatorTest (33 tests): both policies, redirect-URI forms, the https flag, grantable scopes per grant type, grant types, methods, public clients, blank scopes, self-registration's limits, and printable messages.
  • Controller:
    • create refuses a scope its grants cannot get, an authorization_code client without a redirect URI, and a fragment;
    • an update cannot add a scope its grants cannot get, and nothing is saved or audited;
    • http is refused where https is required.
  • OAuthAdminControllerTest: the token is taken only from the form body; a query string or a body without a token is 400 and nothing is looked up.
  • The RFC 7591 registration integration test passes unchanged, with the same invalid_client_metadata refusals.
  • PostgreSQL: the reporting views, the function and the index are gone after V14.
  • Full AS suite: 748 tests, 0 failures (WSL, Docker).

Code review

Round 1 (/code-review high, whole PR): three important findings and three nits, all fixed in 6f4896b (docs: 2180605).

# Finding Resolution
1 A null grant type or authentication method ([null]) was 500: Set.of/List.of throw on contains(null) Fixed: nulls in every list are refused (400) before any lookup; tests for each list and for absent lists
2 An update with redirect_uris:[null] was 500: Spring's builder fails before the validator runs Fixed: refused (400) before the client is built; test
3 An update re-checked the whole stored client, so a client with data from before the rules (the seed's Upload_Admin_Access, a com.example.espi:// redirect URI, http under prod) could not even be renamed Fixed: an update checks only the redirect URIs and scopes it sets, against the client's grant types; test with such a client
4 (nit) A redirect URI with an underscore host (Docker http://third_party:9090/...) was refused Fixed: the authority's host is read when Java gives none; a URI with no host is still refused
5 (nit) A revoke request with an empty body got Spring's default 400 Fixed: the documented token is required
6 (nit) Two assertThat calls on one response Fixed: one chain

Round 2 (/code-review xhigh, scoped to 6f4896b and 2180605): no new runtime bug; one test gap, one finding that predates this PR, four nits. All fixed in 1ac121f (docs: 4b03529).

# Finding Resolution
1 The round-1 test for (3) never used the legacy client it built: the update() helper re-stubbed the ordinary one Fixed: the test calls the endpoint directly and checks the saved client keeps its legacy redirect URI and scope
2 (predates this PR) Revoking one token through the admin API was not audited, unlike revoking all of a client's tokens Fixed: audited as token_revoked with the signed-in administrator and the client's client_id, never the token; test
3 (nit) openapi.yaml still described the update re-checking the whole client Fixed
4 (nit) The underscore-host fallback accepted any registry authority (*, %20, ..., a:b:c) Fixed: it must be a host name with an optional numeric port (no port means the scheme's default); test cases
5 (nit) Removing every redirect URI got Spring's "redirectUris cannot be empty" Fixed: an update is checked before the client is built, so it gets the shared rule's message
6 (nit) validateScopes / validateRedirectUris skipped the null check Fixed

Round 3 (/code-review high, scoped to 1ac121f and 4b03529): one real bug in round 2's audit change, one doc problem that predates it, three nits. All fixed in 48f38bd (docs: 78d733a).

# Finding Resolution
1 The client was read for the audit after the token was removed, so a failed read answered 500 for a revocation that was done, and nothing was audited Fixed: the client is read first, so a failed read revokes nothing; tests for the order and the failed read
2 (docs, predates round 3) The locking paragraph under section 8 said a token revocation locks the client's row; only DELETE /clients/{clientId}/tokens does Fixed: the paragraph names it; section 8 says a single-token revocation takes no lock
3 (nit) A client deleted meanwhile put its internal id in the audit's client_id Fixed: client_id is (unknown) (the column is NOT NULL), the internal id is kept under registered_client_id; test
4 (nit) The host fallback accepted a..b, a.-b, 1.2.3.999, ports 0 and 99999 Fixed: dot-separated labels starting and ending with a letter or digit, not all digits, port 1-65535; test cases
5 (nit) A 404 or a failed revocation left no audit trace Fixed: audited as token_revoked with success false, never the token; tests

Round 3 found a real bug, so under CLAUDE.md the automated reviews stopped there and the owner reviewed the design.

Owner design review: the core design is kept: one shared validator, an update checks only what it sets, the token in the form body, locked and audited admin writes. One change: the host-name fallback (added for round 1's nit 4, refined in rounds 2 and 3) is removed in 47c1652. A redirect URI's host is now the one java.net.URI parses (RFC 2396: a host name or an IP address); a Docker service is named with -, not _. Nothing in the repository used an underscore host. Follow-ups filed on #255: #363 (single-token revocation through ClientAdminService, with the row lock), #364 (validateUpdate in the validator), #365 (report clients that break the rules; fix the seeds). CLAUDE.md now says a nit that adds new behaviour in security-sensitive code is filed, not fixed in the same PR (b99b643).

Round 4 (/code-review high, scoped to 47c1652 and b99b643): no real bug; five nits and two findings that predate the round. Fixed in 91f4fb3 (docs: 1b67ca1) or filed.

# Finding Resolution
1 (nit) http://third_party:9090/cb was refused as "(an absolute http or https URI)", which it is Fixed: an http(s) URI without a host gets "(no host name: use letters, digits and '-', or an IP address)"; test
2 (nit) The comment, guide and a test name said RFC 1123; java.net.URI follows RFC 2396 Fixed: worded as "the host as java.net.URI parses it (RFC 2396: a host name or an IP address)"
3 (nit) Only the client management guide said underscore hosts are refused Fixed: also in INTEGRATION_GUIDE.md, openapi.yaml and API_DOCUMENTATION.md
4 (nit) The new review rule must also go into CMDCertification's CLAUDE.md, kept in step with this one Filed: GreenButtonAlliance/CMDCertification#229, for that repository's session
5 (predates round 4) The port 0, 99999 and port test cases were refused only for their underscore host; java.net.URI does no port range check Fixed: the misleading cases are removed. Filed: a port range check, #366
6 (predates round 4) Redirect URIs with user information (https://good.example@evil.example/cb, user:pw@) are accepted Filed: #366 (new behaviour, so not in this PR)
7 (nit) The accepted-host test ran under the administrator policy only Fixed: it runs under both

Full AS suite after round 4: 742 tests, 0 failures (WSL, Docker).

Round 5 (/code-review high, scoped to 91f4fb3 and 1b67ca1): no real bug; four nits and one stale javadoc that predates the round. All fixed in 6b9ed72.

# Finding Resolution
1 (nit) The "no host name" message also appeared when the host was fine and the port was wrong (http://tp.example:port/cb): java.net.URI then gives no host Fixed: "(no valid host: check the host name (letters, digits, '-' and '.', or an IP address) and the port)"; test case
2 (nit) The message left out . from the host name characters Fixed by (1)
3 (nit) No test checked that a non-http(s) URI still gets "(an absolute http or https URI)" Fixed: test for myapp://, javascript:, a relative URI and ftp://, under both policies
4 (nit) The no-host test ran under self-registration only, and not for post-logout redirect URIs Fixed: both policies, both kinds of redirect URI
5 (predates round 5) The espiRegistrationValidator javadoc did not say a host is required Fixed

Full AS suite after round 5: 747 tests, 0 failures (WSL, Docker).

Round 6 (/code-review high, scoped to 6b9ed72): no real bug; one nit, fixed in 38ba1be, and one finding that predates this PR, filed.

# Finding Resolution
1 (nit) The message's list of host-name characters still misled: java.net.URI refuses tp.1example and tp-.example, and an IPv6 address without brackets Fixed: the list is gone: "(no valid host: check the host name and the port)"; test case http://tp.1example/cb
2 (predates this PR) A bad post-logout redirect URI is refused with invalid_redirect_uri, which RFC 7591 defines for redirect_uris only Filed: added to #366 (it changes the response, so not in this PR)

Full AS suite after round 6: 748 tests, 0 failures (WSL, Docker).

Round 7 (/code-review high, scoped to 38ba1be): no findings. No further src/ change, so under CLAUDE.md the review cycle ends here.

🤖 Generated with Claude Code

dfcoffin and others added 10 commits November 30, 2026 18:02
…/oauth2/register; token revocation takes the token in the body; drop stored-status reporting views (#344)

#344 part 3b, code (owner design, 2026-11-30):
- D2: ClientMetadataValidator holds the rules both ways of registering a
  client share: grant types, authentication methods (#332), redirect and
  post-logout redirect URIs (absolute http/https, a host, no fragment; https
  only where espi.security.require-https-redirect-uris is set, #298), and
  scopes the client could be granted through its own grant types, by
  EspiGrantScopePolicy's token-time rule. SELF_REGISTRATION adds the RFC 7591
  Third Party rules (/oauth2/register, unchanged); ADMINISTRATOR is the admin
  API's. Admin create and update now refuse a scope a client could never be
  given (they only logged a warning) and an authorization_code client with no
  redirect URI; an update is checked as the client it would save.
- #360: DELETE /admin/oauth2/tokens/{tokenId} put the access token in the
  URL, which access logs keep. It is now POST /admin/oauth2/tokens/revoke
  with the token in a form body, as RFC 7009 sends it; a query string is
  refused.
- #355 (D4): PostgreSQL V14 drops v_active_clients, v_security_monitoring,
  check_security_violations() and v_active_client_certificates, which counted
  a client on a timed suspension as active, and the partial index
  idx_v_active_clients_status.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e server, and a test keeps them in step (#343)

#344 part 3b, docs:
- openapi.yaml describes every /admin/oauth2 endpoint the controllers serve
  (status, delete, token revocation of a client, POST /tokens/revoke) with the
  server's schemas: PagedClientResponse, ClientDetails, UpdateClientStatusRequest,
  the client API's error body, and the delete and revocation responses; the
  camelCase ClientListResponse / ClientResponse, the stale error, conflict,
  validation and rate-limit responses are gone, and the parts not checked
  against the server are marked so. No OIDC, opaque bearer tokens.
- ClientManagementOpenApiTest checks the response schemas against the DTOs,
  that the spec lists exactly the controllers' admin endpoints, and that every
  $ref resolves.
- API_DOCUMENTATION.md points to the one client API guide instead of a second,
  wrong copy; error formats, certificate clients, rate limiting and the
  non-existent SDKs are corrected. INTEGRATION_GUIDE.md: no certificate-client
  example, the registration rules shared since #344, an opaque token response
  without id_token. OAUTH2_CLIENT_MANAGEMENT_API.md: the shared rules, token
  revocation in the form body, 404 with no body.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… checks only what it sets, underscore hosts, empty revoke body (#344)

- ClientMetadataValidator refuses a null grant type, authentication method,
  response type or scope before any Set.of/List.of lookup (500 -> 400).
- An update refuses a null or blank redirect URI before the client is built.
- An update checks only the redirect URIs or scopes it sets, against the
  client's grant types (validateRedirectUris / validateScopes), so a client
  stored before the shared rules can still be renamed or changed.
- A redirect URI whose host Java does not parse (a Docker service name with an
  underscore) is accepted; one with no host is still refused.
- POST /admin/oauth2/tokens/revoke with an empty body answers its documented
  "token is required".
- One AssertJ chain in createRefusesHttpWhereHttpsIsRequired.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…copes it sets (#344)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n revocation audited, host names, update errors name the API's fields (#344)

- updateChecksOnlyWhatItSets uses the legacy client it builds (the update()
  helper re-stubbed the ordinary one) and checks the saved client keeps its
  legacy redirect URI and scope.
- POST /admin/oauth2/tokens/revoke is audited as token_revoked with the
  signed-in administrator and the client's client_id, never the token.
- A redirect URI host Java does not parse must be a host name (letters,
  digits, '_', '.', '-') with an optional numeric port; *, %20, ... and
  a:b:c are refused.
- An update's redirect URIs and scopes are checked before the client is
  built, so removing every redirect URI gets the shared rule's message.
- validateRedirectUris and validateScopes refuse a null grant type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n is audited (#344)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…en is revoked, every revocation attempt is audited, stricter host names (#344)

- POST /admin/oauth2/tokens/revoke reads the token's client before removing
  the authorization, so a failed read revokes nothing instead of answering 500
  for a revocation that was done and not audited.
- Every attempt is audited as token_revoked under the administrator: a 404 or
  a failure with success false. The client_id is "(unknown)" when the token or
  its client is not found, with the internal id kept in the data. The token is
  never recorded.
- A host Java does not parse must be dot-separated labels that start and end
  with a letter or digit, not all digits, with an optional port 1-65535.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… attempt is audited (#344)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the host-name fallback is removed (#344)

Owner design review of #361: the fallback that read the authority when Java
found no host (for underscore names such as Docker services) was hand-rolled
host parsing in security-sensitive code, and produced findings in two review
rounds. Nothing in the repository uses an underscore host. A redirect URI's
host is now the one java.net.URI parses (an RFC 1123 host name or an IP
address); a Docker service is named with '-', not '_'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-sensitive code is filed, not fixed (#344)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dfcoffin and others added 4 commits December 1, 2026 16:47
…ays so; host test under both policies (#344)

- A redirect URI with an http(s) scheme and no host (e.g. an underscore
  host name) is refused with "(no host name: use letters, digits and '-',
  or an IP address)" instead of "(an absolute http or https URI)".
- The host comment cites RFC 2396, which java.net.URI follows.
- hostNamesPass runs under both policies; the port 0/99999/'port' cases,
  refused only for their underscore host, are removed (port ranges: #366).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…erscore hosts refused in every guide (#344)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ost and the port; both refusal messages tested (#344)

- A redirect URI with an http(s) scheme but no host java.net.URI accepts
  (an underscore host, a non-numeric port, ...) is refused with "(no valid
  host: check the host name (letters, digits, '-' and '.', or an IP
  address) and the port)".
- Tests: a non-http(s) URI gets "(an absolute http or https URI)"; the
  no-host message for redirect and post-logout redirect URIs, under both
  policies.
- espiRegistrationValidator javadoc: a host is required, an underscore
  host name is refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ists host-name characters (#344)

java.net.URI refuses some names made of the listed characters (a last
label starting with a digit, a label ending with '-') and an unbracketed
IPv6 address, so the list misled. The message is now "(no valid host:
check the host name and the port)"; test case http://tp.1example/cb.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dfcoffin
dfcoffin merged commit 4a7b0b4 into main Dec 1, 2026
12 of 13 checks passed
@dfcoffin
dfcoffin deleted the fix/344-shared-client-validation branch December 1, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment